<template>
  <div class="wrapper">
    <el-col :span="24" class="action-bar">
      <el-input v-model="input" class="action-bar-input" placeholder="请输入关键字"></el-input>
      <el-button type="primary" size="medium" @click="search">检索</el-button>
      <el-button type="primary" size="medium" @click="addpackage">添加</el-button>
    </el-col>

    <!--列表-->
    <el-table :data="activityList" highlight-current-row class="el-table-style">
      <el-table-column type="index" width="75" sortable></el-table-column>
      <el-table-column prop="name" label="题库名称" width="400" sortable></el-table-column>
      <el-table-column prop="score" label="总分数" width="200" sortable></el-table-column>
      <el-table-column prop="status" label="状态" min-width="300" sortable>
        <template slot-scope="scope">
          <p>{{scope.row.status==1 ? '启用' : '禁用'}}</p>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="700">
        <template slot-scope="scope">
          <el-button type="primary" class="danger-btn" size="mini" @click="questionSet(scope.row.id)">编辑</el-button>
          <el-button type="danger" class="danger-btn" size="mini" @click="delQuestionsPackage(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24" class="footer-bar">
      <div class="page-code">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="pagesize"
          @current-change="currentChange"
        ></el-pagination>
      </div>
    </el-col>
  </div>
</template>
<script>
  export default {
    name: "questionList",
    data(){
      return {
        input: '',
        activityList: [],
        total: 0,
        pagesize: 10,
        page_id: 1,
        addFormVisible: false
      }
    },
    mounted(){
      this.questionsPackageList()
    },
    methods:{
      //获取题库列表
      async questionsPackageList(){
        let params = {
          page: this.page_id,
          limit: this.pagesize,
          keyword: this.input
        }
        const res = await this.$api.questionsPackageList(params);
        if (res.data.level == 'success'){
          this.activityList = res.data.data;
          this.total = res.data.page_info.total;
        }else {
          this.$message({
            message: res.data.message,
            type: 'warning'
          })
        }
      },
      //删除题库
      async delQuestionsPackage(id){
        let params = {
          id : id
        }
        const res = await this.$api.delQuestionsPackage(params);
        if (res.data.level == 'success'){
          this.$message({
            message: res.data.message,
            type: 'success'
          })
          this.questionsPackageList();
        } else {
          this.$message({
            message: res.data.message,
            type: 'warning'
          })
        }
      },
      //换页按钮
      currentChange(id){
        this.page_id = id;
        this.questionsPackageList();
      },
      //检索
      search(){
        this.questionsPackageList();
      },
      //添加按钮
      addpackage(){
        this.$router.push({
          path:'/addQuestion'
        })
      },
      //详情按钮
      questionSet(id){
        this.$router.push({
          path:'/addQuestion',
          query:{id:id}
        })
      }
    }
  };
</script>
